package com.hong.spring.transaction.config;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@Aspect
public class UserAspect {
 
  
    @Before("execution(* com.hong.spring.transaction.service..*(..))")
    public void befor(JoinPoint joinPoint) throws IOException {
        joinPoint.getSignature().getName();    //获得调用方法名
        System.out.println("前置通知生效");
    }
 
    @AfterReturning("execution(* com.hong.spring.transaction.service..*(..))")
    public void after(JoinPoint joinPoint){
 
    }
 
    @AfterThrowing(value = "execution(* com.hong.spring.transaction.service..*(..))" ,throwing = "e")
    public void aftherThread(Exception e){
        System.out.println("异常通知"+e.getMessage());
    }
 
}